<template>
  <div class="wrap">
    <div class="login">
      <h3>登录界面</h3>
      <hr/>
      <div class="row">
        <div class="left-box">用户名：</div>
        <input v-model="user.username" />
      </div>
      <div class="row">
        <div class="left-box">密码：</div>
        <input  v-model="user.password" />
      </div>
      <div class="btn-row">
        <button class="btn" @click="login">登录</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data(){
    return {
      user:{
        username: '',
        password: ''
      }
    }
  },
  methods:{
    login(){
      // 同步修改vuex的用户数据
      this.$store.commit('setUserInfo', this.user);
      this.$router.push('/home')
    }
  }

}
</script>

<style scoped>
.wrap{
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login{
  width: 400px;
  padding: 20px;
  border: 1px solid #ddd;
  border-radius: 5px;
}
.row{
  display: flex;
  margin-bottom: 5px;
}
.row .left-box{
  height: 40px;
  line-height: 40px;
  background-color: #eee;
  text-align: center;
  margin-right: 10px;
  width: 100px;
}
.row input{
  height: 40px;
  line-height: 40px;
}
.btn{
  padding: 5px 20px;

}
.btn-row{
  margin-top: 10px;
}
</style>